package com.cy.web;

import com.alibaba.fastjson.JSONArray;
import com.cy.Redis.CacheRedisService;
import com.cy.Service.Question1Service;
import com.cy.bean.Question1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import java.util.List;

@Controller
public class QuestionController {

    @Autowired
    private Question1Service question1Service;
    @Autowired
    private CacheRedisService cacheRedisService;

    @RequestMapping("/getQuestion1All")
    public @ResponseBody void getAllQuestion(){
        //连接本地的Redis服务
        Jedis jedis = new Jedis("43.143.77.47",6379);
        /*将获取到的题库列表，使用list的数据类型存入redis*/
        List<Question1> question1s = question1Service.findAllQuestion();
        for (int i = 0; i <question1s.size() ; i++) {
            String question = JSONArray.toJSONString(question1s.get(i));
            jedis.lpush("question1List",question);
        }
    }
}
